import {useState,useEffect} from 'react'
export default function withMouseMove(WrapperComponent){
    return function(props){
        const [position,setPosition]=useState({x:0,y:0})
        useEffect(()=>{
            let timer=null
            const moveHandle=(e)=>{
                if(timer) return;
                timer=setTimeout(() => {
                    setPosition({
                        x:e.clientX,
                        y:e.clientY
                    })
                    timer=null
                }, 50);
            }
            window.addEventListener('mousemove',moveHandle)
            return ()=>window.removeEventListener('mousemove',moveHandle)
        },[])
        return <WrapperComponent position={position} {...props}></WrapperComponent>
    }
}